﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_HelpNava_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            PopulateNava();

    }

    public void PopulateNava()
    {
        drpHelpNava.DataSource = HelpNava.GetAll();
        drpHelpNava.DataTextField = "Title";
        drpHelpNava.DataValueField = "ID";
        drpHelpNava.DataBind();
    }

    public void PopulateHelpDes()
    {
        lv_HelpDesList.DataSource = HelpDes.GetAllConditon(DongDong.Common.Misc.ConvertToInt(drpHelpNava.SelectedValue), txtKey.Text);
        lv_HelpDesList.DataBind();
    }
    protected void lv_HelpDesList_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        HelpDes.Delete(DongDong.Common.Misc.ConvertToInt(lv_HelpDesList.DataKeys[e.ItemIndex].Value));
        PopulateHelpDes();

    }
    protected void lv_HelpDesList_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateHelpDes();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lv_HelpDesList.Items.Count == 0)
            PopulateHelpDes();
    }

    public string PopulateNavaTitleByNavaID(object NavaID)
    {
        string Return = "暂无资料";

        HelpNava objHelpNava = HelpNava.Get(DongDong.Common.Misc.ConvertToInt(NavaID));
        if (objHelpNava != null)
            Return = objHelpNava.Title;
        return Return;
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateHelpDes();
    }
    protected void lv_HelpDesList_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "Up")
        {
            int KeyID = DongDong.Common.Misc.ConvertToInt(e.CommandArgument);
            HelpDes objHelpDes = HelpDes.Get(KeyID);
            if (objHelpDes != null)
            {
                objHelpDes.Rank = System.DateTime.Now;
                objHelpDes.Update();
            }
            PopulateHelpDes();
        }
    }
}